<?php

namespace IDock\Insurance\ZMBX\Response;

use IDock\Http\Response;
use IDock\Printer\NonCar\NonCarProductListPrinter;
use IDock\Printer\NonCar\NonCarProductPrinter;
use IDock\Printer\NonCar\NonCarSubCoveragePrinter;

class NonCarProductListResponse extends AllZMBXResponse
{
    /**
     * @var NonCarProductListPrinter $printer
     */
    public $printer = NonCarProductListPrinter::class;

    public function printerInit(): Response
    {
        $body = $this->getBody();

        foreach ($body['rideAccident'] ?? [] as $item) {

            $productPrinter = new NonCarProductPrinter();
            $productPrinter->productCode = '';
            $productPrinter->productName = '';
            $productPrinter->productType = '';
            $productPrinter->planCode = $item['rideRiskCode'] ?? '';//方案代码
            $productPrinter->planName = $item['rideRiskName'] ?? '';//方案名称
            $productPrinter->maxQuantity = $item['maxQuantity'] ?? '1';//最大购买份数
            $productPrinter->productDesc = [
                'YW'=> '意外险',
                'ZH'=>'组合险',
                'JC'=>'家财险',
                'YL'=>'医疗',
                'GY' => '个意',
                'CR' => '传染'
            ][$item['divideType']] ?? '';

            $productPrinter->argc['divideType'] = $item['divideType'] ?? '';

            foreach ($item['accAmountView'] ?? [] as $sub) {
                $subCoverage = new NonCarSubCoveragePrinter();
                $subCoverage->subCode = '';
                $subCoverage->subName = $sub['insurName'] ?? '';
                $subCoverage->amount = $sub['amountName'] ?? '';
                $subCoverage->premium = '';
                $productPrinter->subCoverageAppend($subCoverage);
            }

            $productPrinter->premium = $item['unitPremium'];
            $productPrinter->unitAmount = $item['unitAmount'];
            $this->printer->productListAppend($productPrinter);
        }

        return $this;
    }
}
